//
//  ShenPiXiangQingShenPiRenTableViewCell.m
//  JuBoCRM
//
//  Created by iMac on 2024/4/2.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "ShenPiXiangQingShenPiRenTableViewCell.h"
#import "ShenPiXiangQingChengYuanTableViewCell.h"
#import "NSDate+Helper.h"
@implementation ShenPiXiangQingShenPiRenTableViewCell{
    NSArray *dataSource;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    [_mainTableView registerNib:[UINib nibWithNibName:@"ShenPiXiangQingChengYuanTableViewCell" bundle:nil] forCellReuseIdentifier:@"ShenPiXiangQingChengYuanTableViewCell"];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ShenPiXiangQingChengYuanTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShenPiXiangQingChengYuanTableViewCell"];
    NSDictionary *dataDic = dataSource[indexPath.row];
    [cell.headImage sd_setImageWithURL:WebImagePath(GetHandleString(dataDic, @"urlImage")) placeholderImage:HeadImagePlaceholder];
    cell.nameLabel.text = GetHandleString(dataDic, @"realname");
    cell.timeLabel.text = [NSDate dateStringFromString:GetHandleString(dataDic, @"examineTime") format:@"yyyy-MM-dd HH:mm:ss" toFormat:@"yyyy-MM-dd HH:mm"];
    
    
    
    if([GetHandleString(dataDic, @"examineTime") length] > 0){
        cell.timeWidth.constant = 135;
    }else{
        cell.timeWidth.constant = 0;
    }
    if([GetHandleString(dataDic, @"examineStatus") length] > 0){
        if([GetHandleString(dataDic, @"examineStatus") integerValue] == 0){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"待审核";
            cell.statusLabel.textColor = rgba(196, 142, 34, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 1){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"通过";
         
            cell.statusLabel.textColor = rgba(51, 196, 34, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 2){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"拒绝";
           
            cell.statusLabel.textColor = rgba(255, 0, 0, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 3){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"审核中";
     
            cell.statusLabel.textColor = rgba(255, 137, 0, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 4){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"撤回";
           
            cell.statusLabel.textColor = rgba(90, 98, 112, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 5){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"未提交";
          
            cell.statusLabel.textColor = rgba(184, 184, 184, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 6){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"创建";
            cell.statusLabel.textColor = rgba(40, 120, 255, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 7){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"删除";
       
            cell.statusLabel.textColor = rgba(184, 184, 184, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 8){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"作废";
     
            cell.statusLabel.textColor = rgba(184, 184, 184, 1);
        }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 10){
            //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
            cell.statusLabel.text = @"忽略";

            cell.statusLabel.textColor = rgba(184, 184, 184, 1);
        }
    }else{
        cell.statusLabel.text = @"";
    }
    
    if([GetHandleString(dataDic, @"examineStatus") integerValue] == 3){
        cell.timeLabel.hidden = YES;
    }else{
        cell.timeLabel.hidden = NO;
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (void)setModel:(AllModel *)model{
    _model = model;
    
    NSDictionary *dataDic = model.modelInfoDictionary;
        
    _contentLabel.text = GetHandleString(dataDic, @"remark");
    
    if(model.isSelect){
        if([GetHandleString(dataDic, @"name") length] > 0){
            _nameLabel.text = GetHandleString(dataDic, @"name");
        }else{
            _nameLabel.text = @"发起人";
        }
        _timeLabel.text = @"发起审批";
        _topLineImage.hidden = YES;
    }else{
        _topLineImage.hidden = NO;
        _nameLabel.text = GetHandleString(dataDic, @"name");
        if([GetHandleString(dataDic, @"type") intValue] == 1){
            _timeLabel.text = [NSString stringWithFormat:@"%ld人依次审批",[[dataDic objectForKey:@"userList"] count]];
        }else if([GetHandleString(dataDic, @"type") intValue] == 2){
            _timeLabel.text = [NSString stringWithFormat:@"%ld人会签审批",[[dataDic objectForKey:@"userList"] count]];
        }else if([GetHandleString(dataDic, @"type") intValue] == 3){
            _timeLabel.text = [NSString stringWithFormat:@"%ld人或签审批",[[dataDic objectForKey:@"userList"] count]];
        }
    }
    
    
    dataSource = [dataDic objectForKey:@"userList"];
    
    [_mainTableView reloadData];
    
    _tableViewHeight.constant = 44*dataSource.count;
   
    
    _statusImage.sd_layout
    .leftSpaceToView(self.contentView, 16)
    .topSpaceToView(self.contentView, 10)
    .heightIs(40)
    .widthIs(40);
    
 
    
    _topLineImage.sd_layout
    .centerXEqualToView(_statusImage)
    .topSpaceToView(self.contentView, 0)
    .bottomSpaceToView(_statusImage, 0)
    .widthIs(0.5);
    
    _bottomLineImage.sd_layout
    .centerXEqualToView(_statusImage)
    .topSpaceToView(_statusImage, 0)
    .bottomSpaceToView(self.contentView, 0)
    .widthIs(0.5);
    
    
    if(_contentLabel.text.length > 0){
        _contentLabel.sd_layout
        .leftEqualToView(_nameLabel)
        .topSpaceToView(_mainTableView, 6)
        .rightSpaceToView(self.contentView, 16)
        .autoHeightRatio(0);
        
        [self setupAutoHeightWithBottomView:_contentLabel bottomMargin:8];
        
    }else{
        _contentLabel.sd_layout
        .leftEqualToView(_nameLabel)
        .topSpaceToView(_mainTableView, 0)
        .rightSpaceToView(self.contentView, 16)
        .autoHeightRatio(0);
        
        [self setupAutoHeightWithBottomView:_mainTableView bottomMargin:6];
    }
    
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
